package team.southcat.wsyygh.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import team.southcat.wsyygh.common.result.Result;
import team.southcat.wsyygh.model.pojo.user.Admin;
import team.southcat.wsyygh.user.mapper.AdminMapper;
import team.southcat.wsyygh.user.service.AdminService;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements AdminService {
    /**
     * 根据管理员账号获取管理员信息
     * @return
     */
    @Override
    public Admin getByAdminName(String adminName) {
        LambdaQueryWrapper<Admin> queryWrapper = new LambdaQueryWrapper();
        queryWrapper.eq(StringUtils.isNotEmpty(adminName), Admin::getAdminName, adminName);
        Admin admin = baseMapper.selectOne(queryWrapper);
        return admin;
    }

    @Override
    public Result addAdmin(Admin admin) {
        int insert = baseMapper.insert(admin);
        return insert == 1 ? Result.ok() : Result.fail().message("保存失败！");
    }
}
